/**
 * 系统管理API
 */
import { request } from '@/utils/request'

// 用户管理API
export const userManageApi = {
  // 获取用户列表
  getUserList: (params?: any) => {
    return request.get('/auth/users/', { params })
  },

  // 创建用户
  createUser: (data: any) => {
    return request.post('/auth/users/', data)
  },

  // 更新用户
  updateUser: (id: number, data: any) => {
    return request.put(`/auth/users/${id}/`, data)
  },

  // 删除用户
  deleteUser: (id: number) => {
    return request.delete(`/auth/users/${id}/`)
  },

  // 重置密码
  resetPassword: (id: number, data?: any) => {
    return request.post(`/auth/users/${id}/reset_password/`, data)
  },

  // 切换用户激活状态
  toggleUserActive: (id: number) => {
    return request.post(`/auth/users/${id}/toggle_active/`)
  },

  // 获取用户统计
  getUserStatistics: () => {
    return request.get('/auth/users/statistics/')
  }
}

// 权限管理API
export const permissionApi = {
  // 获取权限列表
  getPermissionList: (params?: any) => {
    return request.get('/auth/permissions/', { params })
  },

  // 获取权限模块
  getPermissionModules: () => {
    return request.get('/auth/permissions/modules/')
  },

  // 创建权限
  createPermission: (data: any) => {
    return request.post('/auth/permissions/', data)
  },

  // 更新权限
  updatePermission: (id: number, data: any) => {
    return request.put(`/auth/permissions/${id}/`, data)
  },

  // 删除权限
  deletePermission: (id: number) => {
    return request.delete(`/auth/permissions/${id}/`)
  }
}

// 角色权限管理API
export const rolePermissionApi = {
  // 获取角色权限列表
  getRolePermissionList: (params?: any) => {
    return request.get('/auth/role-permissions/', { params })
  },

  // 按角色获取权限
  getRolePermissions: () => {
    return request.get('/auth/role-permissions/by_role/')
  },

  // 批量更新角色权限
  updateRolePermissions: (data: any) => {
    return request.post('/auth/role-permissions/batch_update/', data)
  },

  // 创建角色权限
  createRolePermission: (data: any) => {
    return request.post('/auth/role-permissions/', data)
  },

  // 删除角色权限
  deleteRolePermission: (id: number) => {
    return request.delete(`/auth/role-permissions/${id}/`)
  }
}

// 登录日志API
export const loginLogApi = {
  // 获取登录日志列表
  getLoginLogs: (params?: any) => {
    return request.get('/auth/login-logs/', { params })
  },

  // 获取登录统计
  getStatistics: () => {
    return request.get('/auth/login-logs/statistics/')
  },

  // 导出登录日志
  exportLoginLogs: (params?: any) => {
    return request.get('/auth/login-logs/export/', {
      params,
      responseType: 'blob'
    })
  }
}

// 系统设置API
export const systemSettingApi = {
  // 获取系统设置
  getSystemSettings: () => {
    return request.get('/system/settings/')
  },
  
  // 更新系统设置
  updateSystemSettings: (data: any) => {
    return request.put('/system/settings/', data)
  },
  
  // 获取系统信息
  getSystemInfo: () => {
    return request.get('/system/info/')
  },
  
  // 清理系统缓存
  clearCache: () => {
    return request.post('/system/clear-cache/')
  },
  
  // 备份数据库
  backupDatabase: () => {
    return request.post('/system/backup/')
  },
  
  // 获取备份列表
  getBackupList: () => {
    return request.get('/system/backups/')
  },
  
  // 恢复数据库
  restoreDatabase: (backupId: number) => {
    return request.post(`/system/restore/${backupId}/`)
  }
}

// 审计日志API
export const auditLogApi = {
  // 获取审计日志列表
  getAuditLogs: (params?: any) => {
    return request.get('/audit-logs/', { params })
  },
  
  // 获取审计日志统计
  getAuditStatistics: () => {
    return request.get('/audit-logs/statistics/')
  },
  
  // 导出审计日志
  exportAuditLogs: (params?: any) => {
    return request.get('/audit-logs/export/', {
      params,
      responseType: 'blob'
    })
  }
}

// 系统监控API
export const monitorApi = {
  // 获取系统状态
  getSystemStatus: () => {
    return request.get('/monitor/status/')
  },
  
  // 获取性能指标
  getPerformanceMetrics: (params?: any) => {
    return request.get('/monitor/metrics/', { params })
  },
  
  // 获取错误日志
  getErrorLogs: (params?: any) => {
    return request.get('/monitor/errors/', { params })
  },
  
  // 获取API调用统计
  getApiStatistics: (params?: any) => {
    return request.get('/monitor-stats/', { params })
  }
}

// 数据统计API
export const statisticsApi = {
  // 获取用户统计
  getUserStatistics: (params?: any) => {
    return request.get('/statistics/users/', { params })
  },
  
  // 获取简历统计
  getResumeStatistics: (params?: any) => {
    return request.get('/statistics/resumes/', { params })
  },
  
  // 获取面试统计
  getInterviewStatistics: (params?: any) => {
    return request.get('/statistics/interviews/', { params })
  },
  
  // 获取岗位统计
  getJobStatistics: (params?: any) => {
    return request.get('/statistics/jobs/', { params })
  },
  
  // 获取综合统计
  getOverallStatistics: () => {
    return request.get('/statistics/overall/')
  }
}

// 系统设置API（新增）
export const systemSettingsApi = {
  // 获取系统信息
  getSystemInfo: () => {
    return request.get('/auth/system-settings/system_info/')
  },

  // 获取用户统计
  getUserStatistics: () => {
    return request.get('/auth/system-settings/user_statistics/')
  },

  // 获取学生统计
  getStudentStatistics: () => {
    return request.get('/auth/system-settings/student_statistics/')
  },

  // 获取登录统计
  getLoginStatistics: () => {
    return request.get('/auth/system-settings/login_statistics/')
  },

  // 清理日志
  clearLogs: (data: any) => {
    return request.post('/auth/system-settings/clear_logs/', data)
  },

  // 获取备份信息
  getBackupInfo: () => {
    return request.get('/auth/system-settings/backup_info/')
  }
}
